<template>
  <div class="home-container">
    <!-- 顶部输入区域 -->
    <header class="input-section">
      <div class="input-wrapper">
        <!-- 问候语和AI头像 -->
        <div class="greeting-section">
          <div class="ai-avatar">
            <div class="avatar-core"></div>
            <div class="avatar-glow"></div>
            <div class="avatar-eyes">
              <span></span><span></span>
            </div>
          </div>
          <h1 class="greeting-text">晚上好<span class="highlight-text">同学</span>，有什么可以帮您？</h1>
        </div>

        <!-- 输入框 -->
        <div class="input-container">
          <textarea 
            class="main-input"
            placeholder="我可以协助您完成备课教学过程中的各项任务，请在此处告诉我您的问题~"
            v-model="inputValue"
            @keydown.enter.prevent="handleSubmit"
          ></textarea>
          <div class="input-footer">
            <div class="input-options">
              <button class="option-btn">
                <Icon name="Brain" :size="16" />
                <span>深度思考</span>
              </button>
              <button class="option-btn">
                <Icon name="Globe" :size="16" />
                <span>联网搜索</span>
              </button>
            </div>
            <button class="send-btn" @click="handleSubmit">
              <Icon name="Send" :size="20" />
            </button>
          </div>
        </div>
      </div>
    </header>

    <!-- 功能按钮区域 -->
    <section class="features-section">
      <div class="features-wrapper">
        <div 
          v-for="feature in quickFeatures" 
          :key="feature.id"
          class="feature-pill"
          @click="handleFeatureClick(feature)"
        >
          <div class="feature-icon" :class="feature.colorClass">
            <Icon :name="feature.iconName" :size="20" />
            <span v-if="feature.badge" class="ai-badge">{{ feature.badge }}</span>
          </div>
          <span class="feature-label">{{ feature.label }}</span>
        </div>
      </div>
    </section>

    <!-- 资源卡片区域 -->
    <main class="resources-section">
      <div class="resources-wrapper">
        <div 
          v-for="resource in resources" 
          :key="resource.id"
          class="resource-card"
          @click="handleResourceClick(resource)"
        >
          <div class="resource-header">
            <div class="header-left">
              <div class="resource-icon-box" :class="resource.iconClass">
                <Icon :name="resource.iconName" :size="20" />
              </div>
              <h3 class="resource-title">{{ resource.title }}</h3>
            </div>
            <button class="resource-action">
              {{ resource.actionText }} <span>&gt;</span>
            </button>
          </div>
          <p class="resource-description">{{ resource.description }}</p>
        </div>
      </div>
    </main>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import Icon from '@/components/icons/Icon.vue'

const router = useRouter()
const inputValue = ref('')

interface QuickFeature {
  id: string
  label: string
  iconName: string
  colorClass: string
  badge?: string
  route?: string
}

interface Resource {
  id: string
  title: string
  description: string
  iconName: string
  iconClass: string
  actionText: string
  route?: string
}

const quickFeatures: QuickFeature[] = [
  {
    id: '1',
    label: '作业辅导',
    iconName: 'BookOpen',
    colorClass: 'blue-icon',
    badge: 'AI',
    route: '/tutor'
  },
  {
    id: '2',
    label: '口语陪练',
    iconName: 'Message',
    colorClass: 'purple-icon',
    badge: 'AI',
    route: '/tutor'
  },
  {
    id: '3',
    label: '作文批改',
    iconName: 'FileText',
    colorClass: 'blue-icon',
    badge: 'AI',
    route: '/tutor'
  },
  {
    id: '4',
    label: '错题整理',
    iconName: 'Lightbulb',
    colorClass: 'green-icon',
    route: '/tutor'
  },
  {
    id: '5',
    label: '更多功能',
    iconName: 'Grid',
    colorClass: 'gray-icon',
    route: '/tutor'
  }
]

const resources: Resource[] = [
  {
    id: '1',
    title: '名师课堂',
    description: '海量名师视频课程，覆盖全学科知识点，随时随地查漏补缺',
    iconName: 'Flag',
    iconClass: 'blue-bg',
    actionText: '开始学习',
    route: '/tutor'
  },
  {
    id: '2',
    title: '必刷题库',
    description: '精选历年真题与高频考题，智能推荐个性化练习，高效提分',
    iconName: 'Star',
    iconClass: 'orange-bg',
    actionText: '去刷题',
    route: '/tutor'
  },
  {
    id: '3',
    title: '学习报告',
    description: '全方位分析学习数据，生成专属成长报告，见证每一点进步',
    iconName: 'Users',
    iconClass: 'blue-bg',
    actionText: '查看报告',
    route: '/tutor'
  },
  {
    id: '4',
    title: '资料下载',
    description: '各科知识点汇总、公式大全、思维导图等学习资料免费下载',
    iconName: 'BookOpen',
    iconClass: 'green-bg',
    actionText: '去下载',
    route: '/tutor'
  }
]

const handleSubmit = () => {
  if (inputValue.value.trim()) {
    router.push('/tutor')
  }
}

const handleFeatureClick = (feature: QuickFeature) => {
  if (feature.route) {
    router.push(feature.route)
  }
}

const handleResourceClick = (resource: Resource) => {
  if (resource.route) {
    router.push(resource.route)
  }
}
</script>

<style scoped>
.home-container {
  min-height: 100vh;
  background: linear-gradient(180deg, #eef4ff 0%, #f5f7fa 100%);
  padding: 60px 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 输入区域 */
.input-section {
  max-width: 1000px;
  margin: 0 auto 32px;
}

.greeting-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}

/* AI 头像 - 蓝色球体效果 */
.ai-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-core {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #60a5fa, #2563eb);
  box-shadow: 
    0 0 15px rgba(96, 165, 250, 0.4),
    0 0 30px rgba(96, 165, 250, 0.3),
    0 0 45px rgba(96, 165, 250, 0.2),
    0 4px 12px rgba(37, 99, 235, 0.4);
  position: relative;
  z-index: 2;
}

.avatar-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120%;
  height: 120%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.2) 0%, rgba(59, 130, 246, 0) 70%);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

.avatar-eyes {
  position: absolute;
  z-index: 3;
  display: flex;
  gap: 6px;
  top: 45%;
}

.avatar-eyes span {
  width: 4px;
  height: 6px;
  background: white;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.9); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

.greeting-text {
  font-size: 26px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
  letter-spacing: 0.5px;
}

.highlight-text {
  color: #7c3aed;
  background: linear-gradient(90deg, #7c3aed, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.input-container {
  background: white;
  border-radius: 24px;
  padding: 24px 32px 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 180px;
}

.main-input {
  width: 100%;
  border: none;
  font-size: 16px;
  color: #1f2937;
  background: transparent;
  resize: none;
  flex: 1;
  outline: none;
  font-family: inherit;
  line-height: 1.6;
}

.main-input::placeholder {
  color: #9ca3af;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

.input-options {
  display: flex;
  gap: 12px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s;
}

.option-btn:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.send-btn {
  width: 40px;
  height: 40px;
  background: #2563eb;
  border: none;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.send-btn:hover {
  background: #1d4ed8;
  transform: scale(1.05);
}

/* 功能按钮区域 */
.features-section {
  max-width: 1000px;
  margin: 0 auto 48px;
}

.features-wrapper {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}

.feature-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px 8px 8px;
  background: white;
  border-radius: 32px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  border: 1px solid transparent;
}

.feature-pill:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  border-color: #e5e7eb;
}

.feature-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: white;
}

.feature-icon.blue-icon {
  background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

.feature-icon.purple-icon {
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
}

.feature-icon.green-icon {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
}

.feature-icon.gray-icon {
  background: #e5e7eb;
  color: #6b7280;
}

.ai-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  background: #10b981;
  color: white;
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 600;
  line-height: 1.2;
  transform: scale(0.8);
}

.feature-label {
  font-size: 14px;
  color: #374151;
  font-weight: 500;
}

/* 资源卡片区域 */
.resources-section {
  max-width: 1000px;
  margin: 0 auto;
}

.resources-wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.resource-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid #f3f4f6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.resource-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
  border-color: transparent;
}

.resource-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.resource-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.resource-icon-box.blue-bg {
  background: #4f46e5;
}

.resource-icon-box.orange-bg {
  background: #f59e0b;
}

.resource-icon-box.green-bg {
  background: #10b981;
}

.resource-title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0;
}

.resource-action {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: #2563eb;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.resource-action span {
  font-family: monospace;
  font-weight: bold;
}

.resource-description {
  font-size: 14px;
  color: #6b7280;
  line-height: 1.6;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 768px) {
  .home-container {
    padding: 20px;
  }
  
  .greeting-text {
    font-size: 20px;
  }
  
  .input-container {
    padding: 20px;
  }
  
  .features-wrapper {
    gap: 12px;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 10px;
  }
  
  .feature-pill {
    flex-shrink: 0;
  }
  
  .resources-wrapper {
    grid-template-columns: 1fr;
  }
}
</style>